package edu.xust.web.controller;

import edu.xust.config.*;
import edu.xust.dto.BaseDto;
import edu.xust.dto.MessageEnum;
import edu.xust.entity.Station;
import edu.xust.page.PageInfo;
import edu.xust.service.StationService;

import java.util.List;

/**
 * @auther: zhangxin
 * @Description:
 */
@Controller("/stationController")
public class StationController {

    @Resource
    StationService stationService;

    @RequestMapping("/getStations")
    public BaseDto getAllStation(){

        BaseDto baseDto = new BaseDto(MessageEnum.FINDALLADMINSUCCESS);
        return baseDto;
    }

    @RequestMapping("/getStationById/{sid}")
    @ResponseBody
    public BaseDto getStationById(String sid){
        Station station = stationService.getStationById(sid);
        System.out.println(station);
        BaseDto baseDto = new BaseDto(MessageEnum.FINDALLADMINSUCCESS,station);
        System.out.println(baseDto.getT()+"...");
        return baseDto;
    }

    @RequestMapping("/addStation")
    @ResponseBody
    public BaseDto addStation(@RequestBody Station station){
        station.setSid("1009");
       if(stationService.addStation(station) > 0){
           return new BaseDto(MessageEnum.ADDADMINSUCCESS,station);
       }
        return new BaseDto(MessageEnum.ADDADMINFAIL,station);
    }

    @RequestMapping("/editStation")
    @ResponseBody
    public BaseDto editStation(@RequestBody Station station){
        if(stationService.editStation(station) > 0){
            return new BaseDto(MessageEnum.ADDADMINSUCCESS,station);
        }
        return new BaseDto(MessageEnum.ADDADMINFAIL,station);
    }


    @RequestMapping("/getStationsByPage")
    @ResponseBody
    public BaseDto getStationsByPage(@RequestBody PageInfo pageInfo) throws Exception {
        List<Station> stations = stationService.getStationByPage(pageInfo);
        BaseDto baseDto = new BaseDto(MessageEnum.ADDADMINSUCCESS,stations);
        baseDto.setObj(pageInfo);
        return baseDto;
    }

    @RequestMapping("/deleteStationById/{adid}")
    @ResponseBody
    public BaseDto deleteStationsById(String sic) throws Exception {

        if(stationService.deleteStationById(sic) > 0){
            return new BaseDto(MessageEnum.DELETEADMINSUCCESS);
        }
        return new BaseDto(MessageEnum.DELETEADMINSUCCESS);
    }





}
